﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlPaymentsPlan.ascx.cs" Inherits="Ctl_ctlPaymentsPlan" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>


    <table style="width:100%;" cellpadding ="3" cellspacing ="0">
    <tr>
        <td  style ="font-weight :bold "   >
            &nbsp;</td>
        <td style ="width :20px"  >
            <asp:ImageButton ID="btnClose" runat="server"  ImageUrl="~/images/close.gif" Width="16px" />
        </td>
    </tr>       
    </table>
    
    <table width ="100%" >
    <tr>
            <td   width="25%">
                Контракт:&nbsp;
                &nbsp;
            </td>
            
            <td  >
                    <%# GetContractDescribe()%>
                </td>
        </tr>
        <tr>
            <td width="25%" >
                Клиент:
                &nbsp;
            </td>
            <td  >
                <%# (ContractSupplier().Client==null?"": ContractSupplier().Client .FullName) %>
                &nbsp;</td>
        </tr>
    </table>

<asp:UpdatePanel ID="updPaymentsPlan"   runat="server">
<ContentTemplate >

<table style="width:100%;">
    <tr>
        <td class ="grd_td_item_caption" style ="font-weight :bold " width="25%" >
            График платежей:</td>
        <td class ="grd_td_item_caption" style ="font-weight :bold " >
            &nbsp;</td>
        <td class="grd_td_item_caption" style="font-weight :bold " width="20px">
            &nbsp;</td>
        <td class ="grd_td_item_caption" style ="text-align :center" width="150px">
            Дата</td>
        <td class ="grd_td_item_caption" style ="text-align :center" >
            Сумма</td>
        <td class="grd_td_item_caption" style="text-align :center" width="150px">
            Оплаченно</td>
        <td class ="grd_td_item_caption" style ="text-align :center" width="20px" >
            <asp:ImageButton ID="btnAddPlanItem" runat="server" ImageUrl="~/images/add.png" 
                onclick="ImageButton3_Click" />
        </td>
    </tr>
    
    <asp:ListView ID="lvPaymentsPlan" runat="server" onitemcommand="ItemCommand" 
        onitemediting="ItemEditing" onitemupdating="ItemUpdating" 
        >
    <LayoutTemplate  >  
    </tr><tr runat="server" id="itemPlaceholder" ></tr>              
    </LayoutTemplate>    
    <ItemTemplate >
        <tr style ="text-align :center">
        <td  style ="text-align :right " width="25%">
                        &nbsp;</td>
        <td  style ="text-align :right ">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
         <td style="text-align :right; font-weight :bold  " width="20px">
            <asp:ImageButton ID=btnRemovePayment runat="server" CommandArgument =<%# Eval("ID") %> ImageUrl ="~/images/trash.png" OnClick ="btnRemovePayment_click" />
            <cc1:ConfirmButtonExtender ID=ConfirmButtonExtender1 TargetControlID ="btnRemovePayment" ConfirmText ="Удалить запись?" runat="server">
            </cc1:ConfirmButtonExtender>
            </td>
        <td class ="grd_td_item" width="150px">
            <%# ((DateTime)Eval("Date")).ToShortDateString () %></td>
        <td class ="grd_td_item" width="150px">
            <%# Eval("Summa").ToString() %></td>
        <td class="grd_td_item" style="text-align :center" width="150px">
            <%# GetPaymentsForPeriod(Container.DataItem)%></td>
        <td class ="grd_td_item" width="20px">
            <asp:ImageButton ID=ImageButton2 runat="server" CommandName ="Edit" ImageUrl ="~/images/icon-edit.gif" /></td>
    </tr>
    </ItemTemplate>
    <EditItemTemplate >
        <tr style ="text-align :center">
        <td  style ="text-align :right " width="25%">
                        &nbsp;</td>
        <td  style ="text-align :right ">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
         <td style="text-align :right; font-weight :bold  " width="20px">
            &nbsp
            </td>
        <td class ="grd_td_item" width="150px">
        
            <asp:HiddenField ID=hfID runat="server" Value = <%# Eval("ID") %>/>
            <asp:TextBox ID="txtDate" CssClass ="TextBox" runat="server" Text =<%# ((DateTime)Eval("Date")).ToShortDateString()%>></asp:TextBox>  </td>
            
            <cc1:CalendarExtender ID="txt_dtSignDate_CalendarExtender" Format="dd.MM.yyyy" PopupPosition="BottomRight" runat="server" Enabled="True" TargetControlID="txtDate">
            </cc1:CalendarExtender>
         </td>
        <td class ="grd_td_item" width="150px">
            <asp:TextBox ID="txtSumma" CssClass ="TextBox" runat="server" Text =<%# Bind("Summa")%>></asp:TextBox>  </td>
        <td class="grd_td_item" style="text-align :center" width="150px">
            25000</td>
        <td class ="grd_td_item" width="20px">
            <asp:ImageButton ID=ImageButton2 runat="server" CommandName ="Update" ImageUrl ="~/images/icon-save.gif" /></td>
    </tr>
    </EditItemTemplate>
    
    </asp:ListView> 
    
    <tr>
        <td  style ="font-weight :bold " width="25%" >
            &nbsp;</td>
        <td  style ="font-weight :bold;text-align :right"  >
            Итого:</td>
        <td  style="font-weight :bold " width="20px">
            &nbsp;</td>
        <td  style ="text-align :center" width="150px">
            &nbsp;</td>
        <td  style ="text-align :center" >
            <asp:Label ID="lblPlanSumma" runat="server" Text=<%# GetPlanPaymentsSumma() %>></asp:Label>
        </td>
        <td  style="text-align :center" width="150px">
            <asp:Label ID="lblPaymentSumma" runat="server" Text="<%# GetPaymentsSumma() %>"></asp:Label>
        </td>
        <td  style ="text-align :center" width="20px" >
            &nbsp;</td>
    </tr>
    
    <tr>
        <td style="font-weight :bold " width="25%">
            &nbsp;</td>
        <td style="font-weight :bold;text-align :right">
            &nbsp;</td>
        <td style="font-weight :bold " width="20px">
            &nbsp;</td>
        <td  style="text-align :right ;font-weight :bold " colspan="2">
            Остаток:</td>
        <td  style="text-align :center" width="150px">
            <asp:Label ID="Label3" runat="server" Text="<%# GetRests()%>"></asp:Label>
        </td>
        <td  style="text-align :center" width="20px">
            &nbsp;</td>
    </tr>
    
    <tr>
        <td style="font-weight :bold " width="25%">
            &nbsp;</td>
        <td style="font-weight :bold;text-align :right">
            &nbsp;</td>
        <td style="font-weight :bold " width="20px">
            &nbsp;</td>
        <td style="text-align :right;font-weight :bold"  colspan="2">
            Текущая задолженность:
        </td>
        <td style="text-align :center" width="150px">
            <asp:Label ID="Label4" runat="server" Text="<%# GetCurrentRests()%>"></asp:Label>
        </td>
        <td style="text-align :center" width="20px">
            &nbsp;</td>
    </tr>
    
    <tr>
        <td style="font-weight :bold " width="25%">
            &nbsp;</td>
        <td style="font-weight :bold;text-align :right">
            &nbsp;</td>
        <td style="font-weight :bold " width="20px">
            &nbsp;</td>
        <td colspan="2" style="text-align :right; color: #FF5050;" >
            &nbsp;</td>
        <td colspan="2" style="text-align :center; width: 170px;" width="150px">
            <asp:Button ID="btnSave" runat="server" CssClass="btn_wizard" 
                Text="Сохранить план" onclick="btnSave_Click" />
        </td>
    </tr>
    
</table>


<table style="width: 100%; text-align: center;">
        
        
        <tr>
            <td class ="grd_td_item_caption" style="text-align:left; font-weight :bold  " 
                width="25%">
                Платежи: </td>
            <td class ="grd_td_item_caption" style="text-align:left; font-weight :bold  ">
                &nbsp;</td>
                <td   style="text-align: right; font-weight :bold; width :20px" class ="grd_td_item_caption" >
                &nbsp
                </td>
        <td  style="text-align: right; font-weight :bold; width :20px" class ="grd_td_item_caption">
                </td>
            <td class ="grd_td_item_caption" width="150px" style="text-align: center">
                Дата</td>
            <td class ="grd_td_item_caption" width="150px">
                Сумма
            </td>
            <td class ="grd_td_item_caption" width="20px">
                <asp:ImageButton ID="btnAddPayment0" runat="server" ImageUrl="~/images/add.png" 
                    onclick="btnAddPayment0_Click" />
                &nbsp;
            </td>
        </tr>
       
       <asp:ListView ID="lvPayments" runat="server" onitemcommand="ItemCommand" 
        onitemediting="ItemEditing" onitemupdating="ItemUpdating" 
        >
    <LayoutTemplate  >  
    </tr><tr runat="server" id="itemPlaceholder" ></tr>              
    </LayoutTemplate>  
        <ItemTemplate >
             <tr>
            <td  style="text-align:left; font-weight :bold  " 
                width="25%">
                 </td>
            <td  style="text-align:left; font-weight :bold  ">
                &nbsp;</td>
                <td   style="text-align: right; font-weight :bold; width :20px" >
                </td>
        <td  style="text-align: right; font-weight :bold; width :20px">
                <asp:ImageButton ID="ImageButton1" runat="server" CommandArgument =<%# Eval("ID") %>   ImageUrl="~/images/trash.png" 
                    onclick="btnRemovePayment_Click" />                
                </td>
            <td class ="grd_td_item" width="150px" style="text-align: center">
                <%# ((DateTime)Eval("Date")).ToShortDateString () %></td>
            <td class ="grd_td_item" width="150px">
                <%# Eval("Summa").ToString() %>
            </td>
            <td class ="grd_td_item_caption" width="20px">
                <asp:ImageButton ID="btnEdit" runat="server" ImageUrl="~/images/icon-edit.gif" CommandName ="Edit" CommandArgument =<%# Eval("ID") %> />                
            </td>
        </tr>
        </ItemTemplate>
        <EditItemTemplate >
        <tr>
            <td  style="text-align:left; font-weight :bold  " 
                width="25%">
                 </td>
            <td  style="text-align:left; font-weight :bold  ">
                &nbsp;</td>
                <td   style="text-align: right; font-weight :bold; width :20px" >
                </td>
        <td  style="text-align: right; font-weight :bold; width :20px">
        &nbsp
                </td>
            <td class ="grd_td_item" width="150px" style="text-align: center">
            <asp:HiddenField ID=hfID runat="server" Value = <%# Eval("ID") %>/>
            <asp:TextBox ID="txtDate" CssClass ="TextBox" runat="server" Text =<%# ((DateTime)Eval("Date")).ToShortDateString()%>></asp:TextBox>  </td>
            
            <cc1:CalendarExtender ID="txt_dtSignDate_CalendarExtender" Format="dd.MM.yyyy" PopupPosition="BottomRight" runat="server" Enabled="True" TargetControlID="txtDate">
            </cc1:CalendarExtender>
            </td>
            <td class ="grd_td_item" width="150px">
                <asp:TextBox ID="txtSumma" CssClass ="TextBox" runat="server" Text =<%# Bind("Summa")%>></asp:TextBox> 
            </td>
            <td class ="grd_td_item_caption" width="20px">
                <asp:ImageButton ID="btnSave" runat="server" ImageUrl="~/images/icon-save.gif" CommandName ="Update" CommandArgument =<%# Eval("ID") %>  />                
            </td>
        </tr>
        </EditItemTemplate> 
       </asp:ListView> 
        
       <tr>
            <td  style="text-align:left; font-weight :bold  " 
                width="25%">
                &nbsp;</td>
            <td  style="text-align:left; font-weight :bold  ">
                &nbsp;</td>
                <td   style="text-align: right; font-weight :bold; width :20px" >
                    Итого:</td>
        <td  style="text-align: right; font-weight :bold; width :20px">
                </td>
            <td  width="150px" style="text-align: center">
                &nbsp;</td>
            <td  width="150px">
                <asp:Label ID="lblSumma" runat="server" Text="<%# GetPaymentsSumma()%>"></asp:Label>
            </td>
            <td  width="20px">
                &nbsp;
            </td>
        </tr>
       
        
    </table>
    

</ContentTemplate>
</asp:UpdatePanel>

